package com.dongdongshop.controller;


import com.dongdongshop.data.Result;
import com.dongdongshop.model.TbBrand;
import com.dongdongshop.service.BrandService;
import com.dongdongshop.vo.BrandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("brand")
public class BrandController {

    @Autowired
    private BrandService brandService;


    //条件查询
    @PostMapping
    public Result brandList(@RequestBody BrandVo brandVo){
       List<BrandVo> voList =  brandService.brandList(brandVo);
       return Result.OK().setData(voList);
    }

    //增加
    @PostMapping("addBrand")
    public Result addBrand(@RequestBody BrandVo brandVo){
        brandService.addBrand(brandVo);
        return  Result.OK();
    }

    //删除
    @PostMapping("daleteBrand")
    public Result daleteBrand(Long[] ids){
        try {
            brandService.daleteBrand(ids);
            return Result.OK();
        }catch (Exception e){
            return Result.er();
        }
    }

    //回显
    @PostMapping("findById")
    public Result  findById(Long id){
       BrandVo brandVo =   brandService.findById(id);
        return Result.OK().setData(brandVo);
    }


    //修改
    @PostMapping("updateThis")
    public Result updateThis(@RequestBody BrandVo brandVo){
        try {
            brandService.updateThis(brandVo);
            return Result.OK();
        }catch (Exception e){
            return Result.er();
        }
    }


    //获取品牌数据

    @PostMapping("getbrand")
    public Result getbrand(){
        try {
            List<TbBrand> brandList=  brandService.getbrand();
            return Result.OK().setData(brandList);
        }catch (Exception e){
            return Result.er();
        }
    }
}
